package com.esfak47.mediafetecher.plugin.download;

import com.esfak47.common.extension.URL;
import com.esfak47.common.job.Job;
import com.esfak47.common.lang.Inject;
import com.esfak47.common.utils.StringUtils;
import com.esfak47.mediafetcher.core.constants.Constants;
import com.esfak47.mediafetcher.core.event.EventSender;
import com.esfak47.mediafetcher.core.service.JobBuilder;

import java.util.UUID;

/**
 * @author tony
 * @date 2018/5/6
 */
public class DownLoadJobBuilder implements JobBuilder {
    @Inject
    private EventSender eventSender;

    @Override
    public Job createJob(URL url) {
        String downloadUrl = url.getParameter("url");
        String fileName = url.getParameter("fileName");
        String filePath = url.getParameter("filePath", Constants.getPath("download"));
        if (StringUtils.isBlank(downloadUrl) || StringUtils.isBlank(fileName)) {
            return null;
        }
        return new DownloadJob(UUID.randomUUID().toString(), fileName, fileName, filePath, downloadUrl, eventSender);
    }

}
